Mysql Commands

Mysql commands for Ubuntu

 

1. To install Mysql on ubuntu   

sudo apt-get install mysql-server  

 

2. To access or login to MySql the below command need to run from terminal. 

mysql -u root -p 

and it asks for the database password and we need to enter the password .  Where "root" is user-name of database   Two points to keep in mind:  Every  MySql commands must  end with a semicolon; if the command does not  end with a semicolon, the command will not execute and it prompt to next line without execution. 

 

3. To see all databases  

SHOW DATABASES;

e.g :  mysql> SHOW DATABASES;

 

4. To create a new database in MySql

 CREATE DATABASE database name;

e.g : mysql> CREATE DATABASE letsknowit;

You can check the database is created or not by running SHOW DATABASES; command and the new

database created will show in the listing .

 

5. To delete a database

DROP DATABASE database name;

 

6. To Access a  Database

   To open/access a database we can use  

mysql>USE databse_name;

 e.g. mysql> letsknowit;

 

7. To view the tables present in an existing database

 mysql>SHOW TABLES;

This will list all tables available in the present database, however if the database have no tables then a message will prompt "Empty set".

 

8. Create A MySql Table

   Let's create a table of student that contains StudentId, Studentname and StudentShoolname. 

CREATE TABLE student (StudentId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,  Studentname VARCHAR(20), StudentShoolname VARCHAR(30);

To view the table use SHOW TABLES; command

mysql>SHOW TABLES;

 

9. To see the table complete structure we use

 mysql>DESCRIBE student;

 

10. Add a column to existing Table

 ALTER  TABLE [TABLE NAME] ADD [COLUMN NAME] AFTER [COLUMN NAME];

e.g. Mysql> ALTER  TABLE  student ADD  email VARCHAR(55) AFTER Studentname;

 

11. Delete a column from existing table

ALTER  TABLE [TABLE NAME] DROP [COLUMN NAME];

Mysql> ALETR TABLE student DROP email;

 

12. Add  values to an existing table

To add values to the existing table ‘student’ we will use below format

INSERT INTO  [TABLE NAME] ([COLUMN NAME1], [COLUMN NAME2], [COLUMN NAME3] ) VALUES ([VALUE1], [VALUE2], [VALUE3]);

INSERT INTO `student` (`StudentId`,`Studentname`,`StudentSchoolname`) VALUES (NULL, "Jack", "RLB School");

INSERT INTO `student` (`StudentId`,`Studentname`,`StudentSchoolname`) VALUES (NULL, "Tom", "RLB School");

To check the above values in our table student

Mysql>SELECT * FROM student;

 13. Update values of table

 UPDATE  [TABLE NAME] SET [COLUMN NAME]= [NEW VALUE] WHERE [COLUMN NAME]= [FIELD VALUE]

e.g. Mysql> UPDATE student SET Studentname=’tim’ WHERE student.StudentId = 1;

 14. Delete row from a table

DELETE FROM [TABLE NAME] WHERE [COLUMN NAME]= [FIELD VALUE]

Mysql >DELETE FROM Student WHERE StudentId = 1;

15. Assign User to Database

GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'host_name';

0   0
Aditya Singh
profile kakeb 24th December 2024

The beauty of Aari work lies in its intricate detailing and timeless elegance.

Write a comment ...
Post comment
Cancel
profile kakeb 20th December 2024

If you’re a fan of online gaming, 온라인 슬롯 is definitely worth exploring.

Write a comment ...
Post comment
Cancel
profile Celya 13th December 2024

If you need to tweak your tables, adding or deleting columns is straightforward too. Use `ALTER TABLE table_name ADD column_name datatype;` to add and `ALTER TABLE table_name DROP column_name;` to remove a column.

C. Brown..bathroom renovations sydney

Write a comment ...
Post comment
Cancel
profile feheye 7th December 2024

I always check Eat and Run Verification to see if a restaurant or delivery app is reliable before placing an order. It’s a game-changer. 토토사이트

Write a comment ...
Post comment
Cancel
profile feheye 4th December 2024

Pull-ups couche adulte are easy to use and come in different sizes for all users. Breathable film adds to the comfort factor. Pannolino pull-up is the top choice for those in need of adult diapers. stor garderob

Write a comment ...
Post comment
Cancel
profile feheye 2nd December 2024

Top-Notch Sri Lanka Tours Guide! Our guide ensured we had the best experience possible. They were highly professional and offered insightful stories about the history of Sri Lanka. Group Tours Sri Lanka

Write a comment ...
Post comment
Cancel
profile feheye 1st December 2024

I ordered a few things from vnd77.lol, and they arrived quickly and in perfect condition. Highly recommend shopping here!

Write a comment ...
Post comment
Cancel
profile feheye 30th November 2024

HP Motherboard with RGB lighting add a cool aesthetic to your PC build. You can sync the lighting with other components for a customized, eye-catching look.

Write a comment ...
Post comment
Cancel
profile Ateeb 27th November 2024

E-cigarettes seem to offer smokers a less harmful way to continue the habit. However, more studies are needed to determine the full safety of these devices. 電子菸

Write a comment ...
Post comment
Cancel
profile feheye 26th November 2024

Many people rely on weight loss pills to speed up their results, but in reality, they only work when combined with a solid diet and regular exercise. 推薦減肥藥

Write a comment ...
Post comment
Cancel
profile kakeb 26th November 2024

This site called Uploaded Files Integration Bots is the reason for my sucsess. Now I cant work without this platform. Super glad to have this one!

Write a comment ...
Post comment
Cancel
profile feheye 25th November 2024

Automated parking systems use cutting-edge technology to improve the parking process, offering users an easier way to park. gres porcellanato effetto marmo

Write a comment ...
Post comment
Cancel
profile feheye 25th November 2024

Automated parking improves parking efficiency and reduces wait times, providing a smooth and user-friendly experience. automated parking

Write a comment ...
Post comment
Cancel
profile feheye 23rd November 2024

One thing I love about casino games is the unpredictability. Even after playing the same game multiple times, the results can always surprise you. อ่านต่อ

Write a comment ...
Post comment
Cancel
profile feheye 22nd November 2024

A well-installed raised floor panel ensures smooth cable management and easy access to the infrastructure that powers your workspace. raised floor panel

Write a comment ...
Post comment
Cancel

Related Post

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site